package com.yusvn.scm.admin.controller;

import com.alibaba.fastjson.JSONObject;
import com.jfinal.aop.Inject;
import com.jfinal.ext.cors.EnableCORS;
import com.jfinal.plugin.activerecord.Page;
import com.yusvn.scm.admin.service.AdminUserService;
import com.yusvn.scm.common.BaseController;
import com.yusvn.scm.common.kit.RetKit;
import com.yusvn.scm.common.model.SysUser;

/**
 * 用户管理
 * @author liugz
 *
 */
@EnableCORS
public class AdminUserController extends BaseController{

	@Inject
	AdminUserService srv;
	
	public void index() {
		renderJson();
	}
	
	/**
	 * 分页查询用户
	 */
	public void page() {
		Page<SysUser> list = srv.page(getKv());
		
		renderJson(RetKit.ok().setCount(list.getTotalRow()).setData( JSONObject.toJSON(list.getList() ) ) );
	}

	/**
	 * 添加用户
	 */
	public void add() {
		renderJson(srv.add(getRawData()));
	}

	public void update() {
		renderJson(srv.update(getRawData()));
	}

	public void remove() {
		renderJson(srv.remove(getPara("id")));
	}

	public void removeBatch() {
		renderJson(srv.removeBatch(getRawData() ) );
	}
	
	/**
	 * 更新用户状态
	 */
	public void state() {
		renderJson(srv.state(getRawData() ) );
	}
	
	/**
	 * 重置用户密码
	 */
	public void resetPassword() {
		renderJson(srv.resetPassword(getPara("id")));
	}
	
}
